
import os
import shutil
import sys
import time
import math
import json
import zipfile
from subprocess import run
import subprocess
# import thread
# import thread6
sys.path.append('../..')
import FileUtils
import ArrayUtils

curPath = os.getcwd()
print(curPath)

projectPath = os.path.abspath(os.path.join(os.path.dirname(curPath), os.pardir,os.pardir))
print(projectPath)

import platform
sysstr = platform.system()
print(platform)


#把主代码放到子包路径
def moveEngineCodeToSubPackageDir():
	logicCodeFilePath = os.path.join(projectPath,"build/wechatgame/cocos/cocos2d-js-min.js")
	logicCode = FileUtils.readUtf8FileData(logicCodeFilePath)
	#创建子包路径
	engineSubPackageDir = os.path.join(projectPath,"build/wechatgame/subpackages/Engine")
	FileUtils.makedirs(engineSubPackageDir)
	FileUtils.writeToUtf8File(os.path.join(engineSubPackageDir,"game.js"),logicCode)
	#清空原来的主逻辑代码文件
	FileUtils.writeToUtf8File(logicCodeFilePath,"")

#声明子包
def declareSubpackages():
	path = os.path.join(projectPath,"build/wechatgame/game.json")
	jsonData = FileUtils.readJsonFileData(path)
	insertJsonData = FileUtils.readJsonFileData(os.path.join(curPath,"game.json"))
	print("jsonData = ",jsonData)
	print("insertJsonData = ",insertJsonData)
	jsonData["subpackages"].append(insertJsonData)
	FileUtils.writeJsonToFile(path,jsonData)


if __name__ == "__main__":
	moveMainLogicCodeToSubPackageDir()
	declareSubpackages()
	pass



